import message from './index.vue'
import { h, render } from 'vue'
type Oposition = {
  type:'success' | 'error' | 'warning'
  text:string 
  duration?:number
}
export function XtxMessage({ type,text,duration = 2000 }:Oposition){
  const div = document.createElement('div')
  div.setAttribute('class','xtx-message-container')
  document.body.appendChild(div)
  const vnode = h(message,{ type,text })
  render(vnode,div)
  setTimeout(()=>{
     render(null,div)
     div.remove()
  },duration)
}
 XtxMessage.success = function( text:string , duration:number =2000 ){
  XtxMessage({
    type: 'success',
    text,
    duration,
  })
}
XtxMessage.error = function( text:string , duration:number =2000 ){
  XtxMessage({
    type: 'error',
    text,
    duration,
  })
}
XtxMessage.warning = function( text:string , duration:number =2000 ){
  XtxMessage({
    type: 'warning',
    text,
    duration,
  })
}